package Test;

import java.util.Scanner;

public class Test4 {

    private static Object locker = new Object();

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            synchronized (locker){
                System.out.println("t1 wait 之前");
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("t1 wait 之后");
            }
        });

        Thread t2 = new Thread(() -> {
            System.out.println("t2 notify 之前");
            Scanner scan = new Scanner(System.in);
            scan.next();
            //此处不管用户输入什么都可以，主要是通过这个 next ，构造 " 阻塞 "
            synchronized (locker){
                locker.notify();
            }
            System.out.println("t1 notify 之后");
        });

        t1.start();
        t2.start();
    }
}
